package com.atguigu.srb.base.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.function.Predicate;

/**
 * ClassName: Swagger2Config
 * Package: com.atguigu.srb.base.config
 * Description:
 *
 * @Author 王晓龙
 * @Create 2023/3/25 16:35
 * @Version 1.0
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {
    //Swagger2配置文件
    @Bean
    public Docket adminApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                //设置组名
                .groupName("adminApi")
                .apiInfo(apiInfo())
                //设置显示的接口
                .select().paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
    }

    @Bean
    public Docket smsApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                //设置组名
                .groupName("webApi")
                .apiInfo(apiInfo())
                //设置显示的接口
                .select().paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();
    }

    //配置当前组
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("尚融宝后台管理系统-API文档")
                .description("本文档描述了尚融宝后台管理系统的接口")
                .version("1.0")
                //设置文档的联系信息：作者，网站url，邮箱
                .contact(new Contact("Atguigu", "http://atguigu.com", "atguigu@163.com"))
                .build();
    }
}